package com.cyt.web.controller.website;

import cn.hutool.core.util.StrUtil;
import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.base.util.BaseConstant;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.web.controller.base.BaseController;
import com.cyt.website.model.po.WebsiteApplicationCategory;
import com.cyt.website.model.vo.WebsiteApplicationCategoryVo;
import com.cyt.website.model.vo.WebsiteApplicationVo;
import com.cyt.website.service.WebsiteApplicationCategoryService;
import com.cyt.website.service.WebsiteApplicationService;
import com.cyt.website.util.cache.CacheService;
import com.cyt.wx.model.po.WxIndustryCategory;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 官网应用案例管理-官网应用案例管理控制层
 *
 * @author congcong tao
 * @date 2019-8-13 9:49:43
 */
@RestController
public class WebsiteApplicationController extends BaseController {

    @Resource
    private CacheService cacheService;
    @Resource
    private WebsiteApplicationCategoryService websiteApplicationCategoryService;
    @Resource
    private WebsiteApplicationService websiteApplicationService;

    /**
     * 统一跳转
     *
     * @param model 数据模型
     * @return Model
     * @author congcong tao
     * @date 2019-8-13 9:49:43
     */
    @RequestMapping("/website/websiteapplication/*")
    public Model goPage(Model model) {
        return model;
    }

    /**
     * 分页查询
     *
     * @param websiteApplicationVo 接受参数对象
     * @param page 当前页面
     * @param limit 页面数量
     * @return ReturnResult
     * @author congcong tao
     * @date 2019-8-13 9:49:43
     */
    @BaseLog(module = "官网应用案例管理", classz = "官网应用案例管理", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/website/websiteapplication/page", method = RequestMethod.POST)
    public ReturnResult page(WebsiteApplicationVo websiteApplicationVo, int page, int limit) {
        return websiteApplicationService.page(websiteApplicationVo, page, limit);
    }

    /**
     * 跳转添加或编辑界面
     *
     * @param id 主键
     * @return ReturnResult
     * @author congcong tao
     * @date 2019-8-13 9:49:43
     */
    @BaseLog(module = "官网应用案例管理", classz = "官网应用案例管理", methods = "跳转添加或编辑界面", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/website/websiteapplication/getEdit", method = RequestMethod.GET)
    public ModelAndView getEdit(String id) {
        ModelAndView view = new ModelAndView("/website/websiteapplication/websiteApplicationEdit");
        // 需要分类
        List<WxIndustryCategory> categoryList = cacheService.selectWxIndustryCategory();
        if (StrUtil.isNotEmpty(id)) {
            // 需要查看是否选中
            WebsiteApplicationCategoryVo websiteApplicationCategoryVo = new WebsiteApplicationCategoryVo();
            websiteApplicationCategoryVo.setRemoveTag(BaseConstant.REMOVE_TAG_NO);
            List<WebsiteApplicationCategory> applicationCategoryList = websiteApplicationCategoryService.findList(websiteApplicationCategoryVo);
            view.addObject(websiteApplicationService.selectByPrimaryKey(id));
            view.addObject("applicationCategoryList", applicationCategoryList);
        }
        view.addObject("categoryList", categoryList);
        return view;
    }

    /**
     * 保存或更新
     *
     * @param request 请求对象
     * @param websiteApplicationVo 接受参数对象
     * @return ReturnResult
     * @author congcong tao
     * @date 2019-8-13 9:49:43
     */
    @BaseLog(module = "官网应用案例管理", classz = "官网应用案例管理", methods = "保存或更新对象", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/website/websiteapplication/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(HttpServletRequest request, WebsiteApplicationVo websiteApplicationVo) {
        return websiteApplicationService.addOrUpdate(websiteApplicationVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件逻辑删除
     *
     * @param request 请求对象
     * @param websiteApplicationVo 接受参数对象
     * @return ReturnResult
     * @author congcong tao
     * @date 2019-8-13 9:49:43
     */
    @BaseLog(module = "官网应用案例管理", classz = "官网应用案例管理", methods = "逻辑删除对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/website/websiteapplication/remove", method = RequestMethod.GET)
    public ReturnResult remove(HttpServletRequest request, WebsiteApplicationVo websiteApplicationVo) {
        return websiteApplicationService.remove(websiteApplicationVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件物理删除
     *
     * @param request 请求对象
     * @param websiteApplicationVo 接受参数对象
     * @return ReturnResult
     * @author congcong tao
     * @date 2019-8-13 9:49:43
     */
    @BaseLog(module = "官网应用案例管理", classz = "官网应用案例管理", methods = "物理对象对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/website/websiteapplication/delete", method = RequestMethod.GET)
    public ReturnResult delete(HttpServletRequest request, WebsiteApplicationVo websiteApplicationVo) {
        return websiteApplicationService.delete(websiteApplicationVo, acceptCurrentUser(request));
    }
}